#ifndef AVALON_PIPEDWRITER_HPP
#define AVALON_PIPEDWRITER_HPP
#include "Avalon/IO/IO.hpp"
#include "Avalon/IO/Writer.hpp"

namespace Avalon {
namespace IO {

  /*! \class PipedWriter
   *  \brief Writes to a PipedReader.
   *  \author Kamal Mansouri <kranar@hotmail.com>
   */
  class PipedWriter : public Writer {
    public:

      //! Constructs a PipedWriter.
      /*!
        \param destination The PipedReader to connect to.
      */
      PipedWriter(PipedReader* destination);

      virtual ~PipedWriter();

      //! Breaks the pipe.
      void Break();

      virtual Threading::Async<void>::Ptr Write(const void* data, int size);

      virtual Threading::Async<void>::Ptr Write(const Buffer& data);

    private:
      friend class PipedReader;
      boost::shared_ptr<boost::recursive_mutex> m_mutex;
      PipedReader* m_destination;

      void InternalBreak();
  };
}
}

#endif // AVALON_PIPEDWRITER_HPP
